/*=============================================================================
#    The element-comm is a tentative program used to test our ideas.           
#                       Copyright (C)  bgao                                    
#
#     This program is free software; you can redistribute it and/or            
#      modify it under the terms of the GNU General Public License             
#     as published by the Free Software Foundation; either version 2           
#         of the License, or (at your option) any later version.               
#
#     This program is distributed in the hope that it will be useful,          
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            
#             GNU General Public License for more details.                    
#
#    You should have received a copy of the GNU General Public License        
#     along with this program; if not, write to the Free Software             
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,             
#                       MA  02110-1301, USA.                                  
#==============================================================================
# $Id: mac_scan.h 348 2010-11-29 09:01:16Z bgao $ 
#
# $Author: bgao $ 
#
# $Revision: 348 $ 
#
# $Date: 2010-11-29 17:01:16 +0800 (星期一, 29 十一月 2010) $ 
#
# Description: 
#
=============================================================================*/
/*! @file mac_scan.h
 *  @brief This file provides the interfaces for the mac_scan module.
 */
#ifndef _MAC_SCAN_H_
#define _MAC_SCAN_H_

#include "common.h"
#include "buf.h"

/*! the MAC PAN descriptor type */
typedef struct mac_pan_desc_t_ {
    uint16   coord_pan_id;        /*!< the coordinator PAN id */
    addr_t   coord_addr;          /*!< the coordinator address */
    uint8    logic_chnl;          /*!< the logic channel */
    uint8    chnl_page;           /*!< the channle page */
    uint16   sup_frm_spec_value;  /*!< the superframe specification value */  
    bool     gts_permit;          /*!< flag indicates if the GTS is permit */
    uint8    link_quality;        /*!< the link quality of the received beacon */
    /* as security is not supported, the security related members are omitted */
} mac_pan_desc_t;

/*! MAC scan status */
typedef enum mac_scan_status_t_ {
    SUCCESS,
    LIMIT_REACHED,
    NO_BCN,
    SCAN_IN_PROGRESS,
    COUNTER_ERR,
    FRM_TOO_LONG,
    INVALID_PARAM
} mac_scan_status_t;

/*! MAC scan type */
typedef enum mac_scan_type_t_ {
    mac_ed_scan_type      = 0x00,
    mac_active_scan_type  = 0x01,
    mac_passive_scan_type = 0x02,
    mac_orphan_scan_type  = 0x03
} mac_scan_type_t;

/*! so as to make the expression to be easy, the following structures
 *  are introduced, which stored the information of the scanned channels.
 */
typedef struct mac_scan_chnls_t_ {
    uint8 *chnls;
    uint8 num;
} mac_scan_chnls_t;

/*! MAC scan request type */
typedef struct mac_scan_req_t_ {
    mac_scan_type_t   scan_type;
    uint8             scan_duration;
    mac_scan_chnls_t  scan_chnls;
    /* as security is not supported, the security related members are omitted */
} mac_scan_req_t;

/*! MAC scan confirm type */
typedef struct mac_scan_cfm_t_ {
    mac_scan_status_t   status;
    mac_scan_type_t     scan_type;
    mac_scan_chnls_t    scan_chnls;
    /* useless I think at present, so comment out */
    //uint8               chanl_page;
    //uint32              unscanned_chnls;
    uint8               result_list_size;
    int8               *energy_detect_list;
    mac_pan_desc_t      *pan_desc_list;
} mac_scan_cfm_t;

/*! MAC beacon notification type */
typedef struct mac_bcn_ntf_t_ {
    uint8            bsn;
    mac_pan_desc_t   pan_desc;
    uint8            pend_addr_spec;
    addr_t           *addr_list;
    uint8            sdu_length;
    uint8            *sdu;
} mac_bcn_ntf_t;

int8 mac_scan_req(mac_scan_req_t *req);

/* specific channel scan methods */
int8 mac_ed_scan(mac_scan_req_t *req);
int8 mac_active_scan(mac_scan_req_t *req);
int8 mac_passive_scan(mac_scan_req_t *req);
int8 mac_orphan_scan(mac_scan_req_t *req);

#endif /* _MAC_SCAN_H_ */
